<?php
namespace app\zucai\admin;
use app\admin\controller\Admin;
use app\common\builder\ZBuilder;
use think\Db;

/**
 * zucai 后台模块
 */
class Play extends Admin
{
    public function index(){

        // 获取排序
        $order = $this->getOrder();

        // 获取筛选
        $map = $this->getMap();

        if (!$order) $order='id desc';

        $data=Db::name('play')->order($order)->where($map)->paginate(30);

        return ZBuilder::make('table')
            ->addFilter('title,team,team2,id')
            ->addFilter('status',['未开奖','已开奖','已取消','异常'])
            ->addOrder('firsttime')
            ->hideCheckbox()
            ->setTableName('play')
            ->addColumns([
                ['id','赛事ID'],
                ['cid','彩种类型','callback',function($cid){
                    $cname=Db::name('caizhong')->where('id',$cid)->field('name')->find();
                    return $cname['name'];
                }],
                ['title','赛事名称'],
                ['ftitle','赛事编号'],
                ['team', '主场队伍'],
                ['team2','客场队伍'],
                ['teamid','主队排名'],
                ['team2id','客队排名'],
                ['rqcls','主队让球数'],
                ['firsttime','比赛时间'],
                ['update_time','最后更新时间'],
                //['shenfu','(让球)胜平负赔率'],
                //['shenfu2','(不让球)胜平负赔率'],
                //['bifen','比分赔率'],
                //['all','总进球赔率'],
                //['banall','半全场胜平负赔率'],
                ['status','状态','status','',['未开奖','已开奖','已取消:default','异常:danger']],
                //['isopen','是否开启','switch'],
                ['right_button','操作','btn'],
            ])
            ->setRowList($data)
            ->addRightButtons(['edit'=>array('title'=>'详情','icon'=>'fa fa-eye')])
            ->setColumnWidth('team,team2,firsttime', 130)
            ->setColumnWidth('teamid,team2id,shenfu,shenfu2', 150)
            ->setColumnWidth('update_time', 160)
            ->fetch();
    }

    /**
     * @param int $id
     * @return mixed
     * gxq <know1111@vip.qq.com>
     */
    public function edit($id=0)
    {
        $data=Db::name('play')->where('id',$id)->find();

        return ZBuilder::make('form')
            ->addFormItems([
                ['static','title','赛事名称'],
                ['static','ftitle','赛事编号'],
                ['static','team', '主场队伍'],
                ['static','team2','客场队伍'],
                ['static','teamid','主队排名'],
                ['static','team2id','客队排名'],
                ['static','rqcls','主队让球数'],
                ['static','firsttime','比赛时间'],
                ['static', 'shenfu', '(让球)胜平负赔率'],
                ['static','shenfu2','(不让球)胜平负赔率'],
                ['static','bifen','比分赔率'],
                ['static','all','总进球赔率'],
                ['static','banall','半全场胜平负赔率'],
            ])
           
            ->setFormData($data)
            ->hideBtn('submit')
            ->fetch();
    }


}